<?php

namespace app\adminabc\controller;

use app\adminabc\controller\Base;

class Main extends Base {
	public function index() {
		return $this->fetch ();
	}
	function editpwd() {
		$pwd = $this->request->param ( 'pwd' );
		$newpwd = $this->request->param ( 'newpwd' );
		$newpwd2 = $this->request->param ( 'newpwd2' );
		$info = model ( 'User' )->getInfo ( array ([ "id",'=',$this->admin_id ] ) );
		if ($this->request->isPost ()) {
			if ($newpwd != $newpwd2)
				echo json_encode ( array ('code' => 0,'msg' => '新密码和再次密码不一致' ) );
			elseif (md5 ( $pwd ) != $info ['password']) {
				echo json_encode ( array ('code' => 0,'msg' => '原密码错误' ) );
			} else {
				$log = model ( 'User' )->editUser ( $this->admin_id, array ('password' => md5 ( $newpwd ) ) );
				if ($log > 0) {
					$_SESSION ['user_pwd'] = md5 ( $newpwd );
					echo json_encode ( array ('code' => 1,'msg' => '修改成功' ) );
				} else
					echo json_encode ( array ('code' => 0,'msg' => '修改失败' ) );
			}
		} else {
			
			return $this->fetch ();
		}
	}
	function welcome() {
		return $this->fetch ( 'welcome' );
	}
	function home() {
		$this->assign ( 'ip', get_client_ip () );
		return $this->fetch ();
	}
}